
'use strict'
export * from './linked-list';

/**
 * @method deepClone
 * @description 深拷贝对象数据
 * @author hjp
 * @date 02/07/2021
 * @param {*} [obj] 对象或者数组
 * @returns {*} 新数据
 */
export function deepClone (obj) {
  const _toString = Object.prototype.toString;

  // null, undefined, non-object, function
  if (!obj || typeof obj !== 'object') {
    return obj;
  }

  // DOM Node
  if (obj.nodeType && 'cloneNode' in obj) {
    return obj.cloneNode(true);
  }

  // Date
  if (_toString.call(obj) === '[object Date]') {
    return new Date(obj.getTime());
  }

  // RegExp
  if (_toString.call(obj) === '[object RegExp]') {
    const flags = [];
    if (obj.global) {
      flags.push('g');
    }
    if (obj.multiline) {
      flags.push('m');
    }
    if (obj.ignoreCase) {
      flags.push('i');
    }

    return new RegExp(obj.source, flags.join(''));
  }

  const result = Array.isArray(obj) ? [] : obj.constructor ? new obj.constructor() : {};
  for (const key in obj) {
    result[key] = deepClone(obj[key]);
  }

  return result;
}


/**
 * @method uuID
 * @description 生成唯一标识字符串
 * @author yanghaiyang
 * @date 2021-07-23 14:40
 * @returns {String} uuid
 */
export function uuID () {
  let d = new Date().getTime();
  const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
    const r = (d + Math.random() * 16) % 16 | 0;
    d = Math.floor(d / 16);
    return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
  });
  return uuid;
}


